package com.bookshop.util;

import com.bookshop.entity.User;
import com.bookshop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component("getIdUtil")
public class GetIdUtil {

    @Autowired
    private UserService userService;

    public Integer getId(HttpServletRequest request)
    {
        String token = request.getHeader("Authorization");
        String phoneNumber = JWTUtil.getUsername(token);
        User user = userService.getUserByPhoneNumber(phoneNumber);

        return  Integer.parseInt(String.valueOf(user.getId()));
    }
}
